﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Portal.Entity;
using ProcessControl.Entity;
using ProcessControl.Logic;
using ProcessControl;
using System.Data;
using MyLib;

namespace CapexProcess
{
    public partial class ApprovalCapexProcess : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string StrStepName = Request.QueryString["StepName"];
            string StrTotalAmount = fld_TOTALAMOUNT.Text.Trim();            
            //((ButtonList)this.ButtonList1).AfterSubmit += new System.ComponentModel.CancelEventHandler(ApprovalCapexProcess_AfterSubmit);
            //if (!IsPostBack)
            //{
            //    txt_NTOTALINV.PreRender += new EventHandler(GetProjectAnalysisData);  //页面加载完之前，最后一个执行该方法
            //}
        }

        void ApprovalCapexProcess_AfterSubmit(object sender, System.ComponentModel.CancelEventArgs e)
        {
            string StrStepName = Request.QueryString["StepName"];
            string StrTotalAmount = fld_TOTALAMOUNT.Text.Trim();
            if (StrStepName == "GM")
            {
                UpdateCapexStatus();
            }
            if (StrStepName == "Finance Manager" || StrStepName == "Finance Operation Manager" || StrStepName == "Finance Control Manager")
            {
                if (int.Parse(StrTotalAmount) < 5000)
                {
                    UpdateCapexStatus();
                }
            }

        }

        public void UpdateCapexStatus()
        {
            try
            {
                //string strResult = "";
                //  DataTable dt = null;
                //  string strSql = "update dbo.PROC_CAPEX set STATUS=2 where DOCUMENTNO='""' ";
                //  dt = DataAccess.Instance("BizDB").ExecuteDataTable(strSql);
            }
            catch (Exception ex)
            {

                string strMessage = ex.Message;
            }
        }

        //protected void GetProjectAnalysisData(object sender, EventArgs e)
        //{
        //    UserInfo userInfo = Page.FindControl("UserInfo1") as UserInfo;
        //    string strSql = "select   FORMID,NTOTALINV,NLOCALEDT,NGLOBALEDT,NOPERATIONPROFIT,NROI,"
        //                 + "  CTOTALINV,CLOCALEDT,CGLOBALEDT,COPERATIONPROFIT,CROI,PROJECTCOMMENT from PROC_CAPEX_PROJECT where FORMID='" + userInfo.FormId.Trim() + "'";
        //    DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable(strSql);
        //    if (dt.Rows.Count > 0)
        //    {
        //        txt_NTOTALINV.Text = dt.Rows[0]["NTOTALINV"].ToString();
        //        txt_NLOCALEDT.Text = dt.Rows[0]["NLOCALEDT"].ToString();
        //        txt_NGLOBALEDT.Text = dt.Rows[0]["NGLOBALEDT"].ToString();
        //        txt_NOPERATIONPROFIT.Text = dt.Rows[0]["NOPERATIONPROFIT"].ToString();
        //        txt_NROI.Text = dt.Rows[0]["NROI"].ToString();
        //        txt_CTOTALINV.Text = dt.Rows[0]["CTOTALINV"].ToString();
        //        txt_CLOCALEDT.Text = dt.Rows[0]["CLOCALEDT"].ToString();
        //        txt_CGLOBALEDT.Text = dt.Rows[0]["CGLOBALEDT"].ToString();
        //        txt_COPERATIONPROFIT.Text = dt.Rows[0]["COPERATIONPROFIT"].ToString();
        //        txt_CROT.Text = dt.Rows[0]["CROI"].ToString();
        //        txt_PROJECTCOMMENT.Text = dt.Rows[0]["PROJECTCOMMENT"].ToString();
        //    }
        //}
    }
}